package com.dragon.pear.models.mock;

import java.io.Serializable;
import java.util.List;

/**
 * @author Chris Chan
 * Create On 2025/7/29 下午7:44
 * Use for:
 * Explain:
 */
public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private long page;

    private long pageSize;

    private long total;

    private boolean hasNext;

    private List<T> dataList;

    public PageResult() {
    }

    public PageResult(long page, long pageSize, long total, boolean hasNext, List<T> dataList) {
        this.page = page;
        this.pageSize = pageSize;
        this.total = total;
        this.hasNext = hasNext;
        this.dataList = dataList;
    }

    public static <T> PageResult<T> of(long page, long pageSize, long total, boolean hasNext, List<T> dataList) {
        return new PageResult<>(page, pageSize, total, hasNext, dataList);
    }

    public static <T> PageResult<T> of(long page, long total, List<T> dataList) {
        long pageSize = dataList.size();
        boolean hasNext = total > pageSize * page;
        return new PageResult<>(page, pageSize, total, hasNext, dataList);
    }

    public static <T> PageResult<T> ofNull() {
        return new PageResult<>(0, 0, 0, false, null);
    }

    public static <T> PageResult<T> buildNull() {
        return PageResult.ofNull();
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }
}
